package com.android.kotlin.activity

import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import com.android.kotlin.R
import com.android.kotlin.util.Constant.USERNAME_KEY
import com.android.kotlin.util.user.LoginSucListener
import com.android.kotlin.util.user.LoginSucState
import com.android.kotlin.util.Preference
import kotlinx.android.synthetic.main.activity_two.*
import org.jetbrains.anko.startActivity

class TwoActivity : AppCompatActivity(), LoginSucListener {

    private var mUsername:String by Preference(USERNAME_KEY, "未登录")
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_two)
        username.text=mUsername

        login.setOnClickListener {
            startActivity<LoginActivity>()
        }
        LoginSucState.addListener(this)
    }


    override fun success(name: String, collectIds: List<Int>?) {
        username.text=name
    }


    override fun onDestroy() {
        super.onDestroy()
        LoginSucState.removeListener(this)
    }
}
